#-*-coding:utf-8-*-
# 1 两数之和
# 给定数组nums和target 找出和为target的两个数,并且返回下标
# method01 :两层for循环解决问题
# method2 :利用dict保存已经遍历过得数据


from day03 import calRunTime

@calRunTime
def getTwoNumber(arr,target):
	idx0,idx1 = -1,-1
	if not arr:
		return idx0,idx1
	totalCount = len(arr)
	for i in xrange(0,totalCount-1):
		for j in xrange(1,totalCount):
			if arr[i] + arr[j] == target:
				idx0 = i
				idx1 = j
				break

	return idx0,idx1


@calRunTime
def hashMapGetTwoNumber(arr,target):
	tmpDict = {}
	for idx,num in enumerate(arr):
		secNum = target - num
		if tmpDict.has_key(secNum):
			return idx,tmpDict[secNum]
		else:
			tmpDict.update({num:idx})
	return (-1,-1)

if __name__ == "__main__":
	#ret = getTwoNumber([1,2,3,4,5],3)
	ret = hashMapGetTwoNumber([1,2,3,4,5],3)
	print ret